package net.peihuan.controller;

import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class LoginController {

    @RequestMapping("/loginVerify")
    @ResponseBody
    public int loginVerify(HttpServletRequest request, HttpServletResponse response){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        int result;
        if("我爱你".equals(username)&&"world".equals(password)){
            //添加session
            request.getSession().setAttribute("user", "pei");
            result=1;
        }else{
            result=0;
        }
        return result;
    }

    @RequestMapping("/logout")
    public ModelAndView loginView(HttpSession session) {
        session.invalidate();                           //注销session
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/login.html");
        return modelAndView;
    }

}
